﻿using Microsoft.AspNetCore.Http;
using System.Net;
using System.Threading.Tasks;

namespace Micro.Extensions.Bridge
{
    public class HealthMiddleware
    {
        private readonly RequestDelegate _next;
        private readonly string _healthPath = "/health";
        public HealthMiddleware(RequestDelegate next)
        {

            _next = next;
        }

        public async Task InvokeAsync(HttpContext context)
        {
            if (context.Request.Path == _healthPath)
            {

                context.Response.StatusCode = (int)HttpStatusCode.OK;
                await context.Response.WriteAsync("I'm OK!");
            }
            else
            {
                await _next(context);
            }

        }
    }
}
